package com.kgc.smbms.utils;

import java.util.List;

public class PageSupport<T> {
	//当前页,显示页码
	private int currPageNo = 1;
	
	//页面容量
	private int pageSize = 5;

	//总条数(带条件查询的总条数)
	private int totalCount;
	
	//总页数(根据总条数和页面容量)
	private int totalPage;
    
	//分页条件查询的数据
	private T data;

	//回显 查询数据
	private List<String> callBackInfo;

	//排序字段
	private  String orderBy = "id";

	//升序 还是 降序
	private String ascOrDesc = "asc";

	//设置总条数的时候  计算总页数
    public void setTotalCount(int totalCount) {
		//当存在总条数,确定总页数
		this.totalCount = totalCount;
		//计算总页数
		this.totalPage = this.totalCount % this.pageSize == 0 ?
				this.totalCount / this.pageSize :
					this.totalCount / this.pageSize + 1;
	}

	public int getCurrPageNo() {
		return currPageNo;
	}

	public void setCurrPageNo(int currPageNo) {
		//页码特殊处理
		if(currPageNo < 1 || this.totalCount == 0 ){
			currPageNo = 1;
		}else if(currPageNo > this.totalPage){
			currPageNo = this.getTotalPage();
		}
		this.currPageNo = currPageNo;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public List<String> getCallBackInfo() {
		return callBackInfo;
	}

	public void setCallBackInfo(List<String> callBackInfo) {
		this.callBackInfo = callBackInfo;
	}

	public String getOrderBy() {
		return orderBy;
	}

	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}

	public String getAscOrDesc() {
		return ascOrDesc;
	}

	public void setAscOrDesc(String ascOrDesc) {
		this.ascOrDesc = ascOrDesc;
	}

	@Override
	public String toString() {
		return "PageSupport{" +
				"currPageNo=" + currPageNo +
				", pageSize=" + pageSize +
				", totalCount=" + totalCount +
				", totalPage=" + totalPage +
				", data=" + data +
				", callBackInfo=" + callBackInfo +
				", orderBy='" + orderBy + '\'' +
				", ascOrDesc='" + ascOrDesc + '\'' +
				'}';
	}
}